package view.product;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.border.TitledBorder;

import lib.MyUtils;
import controller.product.SupplierControl;

public class ProductSupplierPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private JButton btnProdsupAdd;
	private JButton btnProdsupCancel;
	private JButton btnProdsupDelete;
	private JButton btnProdsupEdit;
	private JButton btnProdsupSearch;
	private JButton btnProdsupUpdate;
	private JComboBox<String> cbbProdsupSearchby;
	private JScrollPane jScrollPane1;
	private JScrollPane jScrollPane2;
	private JLabel lblProdsupAddress;
	private JLabel lblProdsupBy;
	private JLabel lblProdsupId;
	private JLabel lblProdsupPhone;
	private JLabel lblProdsupSuppliername;
	private JPanel pnProdsupInformation;
	private JPanel pnProdsupListcupplier;
	private JTable tblProdsupListsupplier;
	private JTextField txtProdsupId;
	private JTextField txtProdsupPhone;
	private JTextField txtProdsupSearch;
	private JTextField txtProdsupSuppliername;
	private JTextArea txtaProdsupAddress;

	private SupplierControl controller;
	
	public SupplierControl getController() {
		return controller;
	}

	public JButton getBtnProdsupAdd() {
		return btnProdsupAdd;
	}

	public void setBtnProdsupAdd(JButton btnProdsupAdd) {
		this.btnProdsupAdd = btnProdsupAdd;
	}

	public JButton getBtnProdsupCancel() {
		return btnProdsupCancel;
	}

	public void setBtnProdsupCancel(JButton btnProdsupCancel) {
		this.btnProdsupCancel = btnProdsupCancel;
	}

	public JButton getBtnProdsupDelete() {
		return btnProdsupDelete;
	}

	public void setBtnProdsupDelete(JButton btnProdsupDelete) {
		this.btnProdsupDelete = btnProdsupDelete;
	}

	public JButton getBtnProdsupEdit() {
		return btnProdsupEdit;
	}

	public void setBtnProdsupEdit(JButton btnProdsupEdit) {
		this.btnProdsupEdit = btnProdsupEdit;
	}

	public JButton getBtnProdsupSearch() {
		return btnProdsupSearch;
	}

	public void setBtnProdsupSearch(JButton btnProdsupSearch) {
		this.btnProdsupSearch = btnProdsupSearch;
	}

	public JButton getBtnProdsupUpdate() {
		return btnProdsupUpdate;
	}

	public void setBtnProdsupUpdate(JButton btnProdsupUpdate) {
		this.btnProdsupUpdate = btnProdsupUpdate;
	}

	public JComboBox<String> getCbbProdsupSearchby() {
		return cbbProdsupSearchby;
	}

	public void setCbbProdsupSearchby(JComboBox<String> cbbProdsupSearchby) {
		this.cbbProdsupSearchby = cbbProdsupSearchby;
	}

	public JPanel getPnProdsupInformation() {
		return pnProdsupInformation;
	}

	public void setPnProdsupInformation(JPanel pnProdsupInformation) {
		this.pnProdsupInformation = pnProdsupInformation;
	}

	public JPanel getPnProdsupListcupplier() {
		return pnProdsupListcupplier;
	}

	public void setPnProdsupListcupplier(JPanel pnProdsupListcupplier) {
		this.pnProdsupListcupplier = pnProdsupListcupplier;
	}

	public JTable getTblProdsupListsupplier() {
		return tblProdsupListsupplier;
	}

	public void setTblProdsupListsupplier(JTable tblProdsupListsupplier) {
		this.tblProdsupListsupplier = tblProdsupListsupplier;
	}

	public JTextField getTxtProdsupId() {
		return txtProdsupId;
	}

	public void setTxtProdsupId(JTextField txtProdsupId) {
		this.txtProdsupId = txtProdsupId;
	}

	public JTextField getTxtProdsupPhone() {
		return txtProdsupPhone;
	}

	public void setTxtProdsupPhone(JTextField txtProdsupPhone) {
		this.txtProdsupPhone = txtProdsupPhone;
	}

	public JTextField getTxtProdsupSearch() {
		return txtProdsupSearch;
	}

	public void setTxtProdsupSearch(JTextField txtProdsupSearch) {
		this.txtProdsupSearch = txtProdsupSearch;
	}

	public JTextField getTxtProdsupSuppliername() {
		return txtProdsupSuppliername;
	}

	public void setTxtProdsupSuppliername(JTextField txtProdsupSuppliername) {
		this.txtProdsupSuppliername = txtProdsupSuppliername;
	}

	public JTextArea getTxtaProdsupAddress() {
		return txtaProdsupAddress;
	}

	public void setTxtaProdsupAddress(JTextArea txtaProdsupAddress) {
		this.txtaProdsupAddress = txtaProdsupAddress;
	}

	public ProductSupplierPanel() {
		initComponents();
		MyUtils.loadSupplier(this);
	}

	private void initComponents() {
		controller = new SupplierControl(this);
		pnProdsupListcupplier = new JPanel();
		jScrollPane1 = new JScrollPane();
		tblProdsupListsupplier = new JTable();
		txtProdsupSearch = new JTextField();
		lblProdsupBy = new JLabel();
		cbbProdsupSearchby = new JComboBox<String>();
		btnProdsupSearch = new JButton();
		pnProdsupInformation = new JPanel();
		lblProdsupId = new JLabel();
		txtProdsupId = new JTextField();
		txtProdsupSuppliername = new JTextField();
		lblProdsupSuppliername = new JLabel();
		lblProdsupAddress = new JLabel();
		txtProdsupPhone = new JTextField();
		lblProdsupPhone = new JLabel();
		btnProdsupDelete = new JButton();
		btnProdsupUpdate = new JButton();
		btnProdsupEdit = new JButton();
		jScrollPane2 = new JScrollPane();
		txtaProdsupAddress = new JTextArea();
		btnProdsupAdd = new JButton();
		btnProdsupCancel = new JButton();

		setPreferredSize(new java.awt.Dimension(906, 480));

		pnProdsupListcupplier
				.setBackground(new java.awt.Color(255, 255, 255));
		pnProdsupListcupplier.setBorder(BorderFactory.createTitledBorder(
				null, "List Supplier", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue)); 

		tblProdsupListsupplier.setFont(new java.awt.Font("Calibri", 0, 12)); 
		tblProdsupListsupplier.addMouseListener(new SupplierControl(this));
		jScrollPane1.setViewportView(tblProdsupListsupplier);
		

		lblProdsupBy.setText("by");

		cbbProdsupSearchby.setModel(new DefaultComboBoxModel<String>(
				new String[] { "All"}));

		btnProdsupSearch.setFont(new java.awt.Font("Calibri", 1, 12)); 
		btnProdsupSearch
				.setIcon(new ImageIcon(
						"icon/search.png")); 
		btnProdsupSearch.setText("Search");
		btnProdsupSearch.addActionListener(controller);

		GroupLayout pn_prodsup_listcupplierLayout = new GroupLayout(
				pnProdsupListcupplier);
		pnProdsupListcupplier.setLayout(pn_prodsup_listcupplierLayout);
		pn_prodsup_listcupplierLayout
				.setHorizontalGroup(pn_prodsup_listcupplierLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addComponent(jScrollPane1,
								GroupLayout.Alignment.TRAILING)
						.addGroup(
								GroupLayout.Alignment.TRAILING,
								pn_prodsup_listcupplierLayout
										.createSequentialGroup()
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(txtProdsupSearch,
												GroupLayout.PREFERRED_SIZE,
												151, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(lblProdsupBy)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(cbbProdsupSearchby,
												GroupLayout.PREFERRED_SIZE, 79,
												GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(btnProdsupSearch,
												GroupLayout.PREFERRED_SIZE, 90,
												GroupLayout.PREFERRED_SIZE)
										.addContainerGap()));
		pn_prodsup_listcupplierLayout
				.setVerticalGroup(pn_prodsup_listcupplierLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								GroupLayout.Alignment.TRAILING,
								pn_prodsup_listcupplierLayout
										.createSequentialGroup()
										.addGroup(
												pn_prodsup_listcupplierLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtProdsupSearch,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lblProdsupBy)
														.addComponent(
																cbbProdsupSearchby,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnProdsupSearch))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(jScrollPane1,
												GroupLayout.DEFAULT_SIZE, 195,
												Short.MAX_VALUE)));

		pnProdsupInformation.setBackground(new java.awt.Color(255, 255, 255));
		pnProdsupInformation.setBorder(BorderFactory.createTitledBorder(null,
				"Information", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue)); 

		lblProdsupId.setFont(new java.awt.Font("Calibri", 0, 12)); 
		lblProdsupId.setText("ID:");

		lblProdsupSuppliername.setFont(new java.awt.Font("Calibri", 0, 12)); 
		lblProdsupSuppliername.setText("Suplier name:");

		lblProdsupAddress.setFont(new java.awt.Font("Calibri", 0, 12)); 
		lblProdsupAddress.setText("Address:");

		lblProdsupPhone.setFont(new java.awt.Font("Calibri", 0, 12)); 
		lblProdsupPhone.setText("Phone:");

		btnProdsupDelete.setFont(new java.awt.Font("Calibri", 1, 12)); 
		btnProdsupDelete
				.setIcon(new ImageIcon(
						"icon/em_delete.png")); 
		btnProdsupDelete.setText("Delete");
		btnProdsupDelete.addActionListener(controller);
		

		btnProdsupUpdate.setFont(new java.awt.Font("Calibri", 1, 12)); 
		btnProdsupUpdate
				.setIcon(new ImageIcon(
						"icon/save.png")); 
		btnProdsupUpdate.setText("Update");
		btnProdsupUpdate.addActionListener(controller);

		btnProdsupEdit.setFont(new java.awt.Font("Calibri", 1, 12)); 
		btnProdsupEdit
				.setIcon(new ImageIcon(
						"icon/em_edit.png")); 
		btnProdsupEdit.setText("Edit");
		btnProdsupEdit.addActionListener(controller);

		txtaProdsupAddress.setColumns(20);
		txtaProdsupAddress.setRows(5);
		jScrollPane2.setViewportView(txtaProdsupAddress);

		GroupLayout pn_prodsup_informationLayout = new GroupLayout(
				pnProdsupInformation);
		pnProdsupInformation.setLayout(pn_prodsup_informationLayout);
		pn_prodsup_informationLayout
				.setHorizontalGroup(pn_prodsup_informationLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_prodsup_informationLayout
										.createSequentialGroup()
										.addGap(160, 160, 160)
										.addGroup(
												pn_prodsup_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING,
																false)
														.addGroup(
																pn_prodsup_informationLayout
																		.createSequentialGroup()
																		.addComponent(
																				lblProdsupPhone)
																		.addGap(57,
																				57,
																				57)
																		.addComponent(
																				txtProdsupPhone))
														.addGroup(
																pn_prodsup_informationLayout
																		.createSequentialGroup()
																		.addComponent(
																				lblProdsupId)
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.RELATED,
																				GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addComponent(
																				txtProdsupId,
																				GroupLayout.PREFERRED_SIZE,
																				156,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																pn_prodsup_informationLayout
																		.createSequentialGroup()
																		.addComponent(
																				lblProdsupSuppliername)
																		.addGap(18,
																				18,
																				18)
																		.addComponent(
																				txtProdsupSuppliername,
																				GroupLayout.PREFERRED_SIZE,
																				156,
																				GroupLayout.PREFERRED_SIZE)))
										.addGap(48, 48, 48)
										.addComponent(lblProdsupAddress)
										.addGap(27, 27, 27)
										.addComponent(jScrollPane2,
												GroupLayout.PREFERRED_SIZE,
												198, GroupLayout.PREFERRED_SIZE)
										.addContainerGap(138, Short.MAX_VALUE))
						.addGroup(
								GroupLayout.Alignment.TRAILING,
								pn_prodsup_informationLayout
										.createSequentialGroup()
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(btnProdsupEdit,
												GroupLayout.PREFERRED_SIZE,
												100, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(btnProdsupUpdate,
												GroupLayout.PREFERRED_SIZE,
												100, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(btnProdsupDelete,
												GroupLayout.PREFERRED_SIZE,
												100, GroupLayout.PREFERRED_SIZE)
										.addContainerGap()));
		pn_prodsup_informationLayout
				.setVerticalGroup(pn_prodsup_informationLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_prodsup_informationLayout
										.createSequentialGroup()
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												pn_prodsup_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																pn_prodsup_informationLayout
																		.createSequentialGroup()
																		.addGroup(
																				pn_prodsup_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								txtProdsupId,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								lblProdsupId)
																						.addComponent(
																								lblProdsupAddress))
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				pn_prodsup_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								lblProdsupSuppliername)
																						.addComponent(
																								txtProdsupSuppliername,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				pn_prodsup_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								lblProdsupPhone)
																						.addComponent(
																								txtProdsupPhone,
																								GroupLayout.PREFERRED_SIZE,
																								GroupLayout.DEFAULT_SIZE,
																								GroupLayout.PREFERRED_SIZE)))
														.addComponent(
																jScrollPane2,
																GroupLayout.Alignment.TRAILING,
																GroupLayout.PREFERRED_SIZE,
																72,
																GroupLayout.PREFERRED_SIZE))
										.addGap(30, 30, 30)
										.addGroup(
												pn_prodsup_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																btnProdsupEdit,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnProdsupUpdate,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnProdsupDelete,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE))
										.addGap(29, 29, 29)));

		btnProdsupAdd.setFont(new java.awt.Font("Calibri", 1, 15)); 
		btnProdsupAdd
				.setIcon(new ImageIcon(
						"icon/add.png")); 
		btnProdsupAdd.setText("Add");
		btnProdsupAdd.setToolTipText("");
		btnProdsupAdd.addActionListener(controller);

		btnProdsupCancel.setFont(new java.awt.Font("Calibri", 1, 15)); 
		btnProdsupCancel
				.setIcon(new ImageIcon(
						"icon/clear.png")); 
		btnProdsupCancel.setText("Clear");
		btnProdsupCancel.addActionListener(controller);

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addGap(0, 16, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														pnProdsupInformation,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														pnProdsupListcupplier,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addContainerGap())
				.addGroup(
						layout.createSequentialGroup()
								.addGap(347, 347, 347)
								.addComponent(btnProdsupAdd,
										GroupLayout.PREFERRED_SIZE, 90,
										GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(btnProdsupCancel)
								.addContainerGap(GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(pnProdsupInformation,
										GroupLayout.PREFERRED_SIZE, 164,
										GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(pnProdsupListcupplier,
										GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.LEADING)
												.addComponent(
														btnProdsupCancel,
														GroupLayout.PREFERRED_SIZE,
														30,
														GroupLayout.PREFERRED_SIZE)
												.addComponent(
														btnProdsupAdd,
														GroupLayout.PREFERRED_SIZE,
														30,
														GroupLayout.PREFERRED_SIZE))
								.addContainerGap(GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));
	}

}
